import datetime
import Queue

class Event(object):
	def __init__(self, eventCode, eventData, eventContext = None, eventTimestamp = None):
		self._eventCode = eventCode
		self._eventData = eventData
		self._eventContext = eventContext
		if eventTimestamp is None:
			self._eventTimestamp = datetime.datetime.now()
		else:
			self._eventTimestamp = eventTimestamp
	@property
	def eventCode(self): return self._eventCode
	@property
	def eventData(self): return self._eventData
	@property
	def eventContext(self): return self._eventContext
	@property
	def eventTimestamp(self): return self._eventTimestamp

class EventQueue(object):
	def __init__(self):
		self._queuedEvents = Queue.Queue()
	@property
	def numberOfEvents(self):
		return self._queuedEvents.qsize()
	@property
	def noEvents(self):
		return self._queuedEvents.empty()
	def registerEvent(self, e):
		assert isinstance(e, Event), "event data must be a subclass of Event"
		self._queuedEvents.put_nowait(e)
	def nextEvent(self):
		return self._queuedEvents.get_nowait()

